/*
    created:2023/4/19
    filename: Composite.h
    author: 李东霖
    purpose: Composite组合模式的演示代码
*/

#ifndef _COMPOSITE_H_
#define _COMPOSITE_H_

#include<list>
//组合中的抽象基类
class Component
{
public:
    Component();
    virtual ~Component();

    //提供的接口  
    virtual void Operation() = 0;
    //提供接口，有默认的实现但是什么都不做  
    virtual void Add(Component* pChild);
    virtual void Remove(Component* pChild);
    virtual Component* GetChild(int nIndex);
};


//Component的派生，是其中的叶子组件的基类
class Leaf:public Component
{
public:
    Leaf() = default;
    virtual ~Leaf() = default;

    virtual void Operation()override;
};

//Component的派生，是其中的含有子件的组件的基类  
class Composite:public Component
{
public:
    Composite();
    virtual ~Composite();
    
    virtual void Operation();

    virtual void Add(Component* pChild) override;
    virtual void Remove(Component* pChild)override;
    virtual Component* GetChild(int nIndex)override;

private:
    std::list<Component* > m_ListOfComponent;
};


#endif //!_COMPOSITE_H_
